﻿using System;

namespace WindowsPhoneMvp.Phone
{
    /// <summary>
    /// For future use. 
    /// When WindowsPhone gets XAML2009 this will be supported and the Model() extension methods will
    /// become obsolete
    /// </summary>
    public abstract class MvpPhoneApplicationPage<TModel> : MvpPhoneApplicationPage, IView<TModel>
        where TModel : class, new()
    {
        /// <summary>
        /// Gets or sets the view model.
        /// </summary>
        /// <value>The view model.</value>
        public TModel Model
        {
            get
            {
                if (DataContext == null)
                    throw new InvalidOperationException("The Model property is currently null, however it should have been automatically initialized by the presenter. This most likely indicates that no presenter was bound to the control. Check your presenter bindings.");

                return (TModel)DataContext;
            }
            set
            {
                DataContext = value;
            }
        }
    }
}
